#include <iostream>
#include <string>

using namespace std;

struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution
{
public:
    ListNode *deleteDuplicates(ListNode *head)
    {
        ListNode* ptr=head;
        ListNode* first=NULL;
        ListNode* last=NULL;

        while(ptr!=NULL)
            {
                if(ptr->next==NULL||ptr->val!=ptr->next->val)
                    {
                        ListNode* node=new ListNode(ptr->val);
                        if(first==NULL)
                            {
                                first=node;
                                last=node;
                            }
                        else
                            {
                                last->next=node;
                                last=last->next;
                            }
                    }
                ptr=ptr->next;
            }
        return first;
    }
};

void display(ListNode* head)
{
    ListNode* ptr=head;
    while(ptr!=NULL)
        {
            cout<<ptr->val<<",";
            ptr=ptr->next;
        }
    cout<<endl;
}

int main()
{
    Solution s;

    ListNode * head=NULL;
    ListNode * last=NULL;
    int a;
    while(true)
        {
            cin>>a;
            if(a==-1)
                break;
            ListNode* node=new ListNode(a);
            if(head==NULL)
                {
                    head=node;
                    last=node;
                }
            else
                {
                    last->next=node;
                    last=last->next;
                }
        }
    display(head);
    ListNode* first=s.deleteDuplicates(head);
    display(first);
    cout<<"ok!"<<endl;
}